/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ventasimple.web;

import com.mercadopago.MP;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author Claudio
 */
@ManagedBean
@SessionScoped
public class MercadoPago {
    
    MP mp;
    JSONObject preference;
    String checkoutURL;

    /**
     * Creates a new instance of MercadoPago
     */
    public MercadoPago() {
    }
    
    @PostConstruct
    private void init() {
        try {
            mp = new MP ("6045934891828688", "R2VegaY1rCObz9jC0niek4GR9S5ujIfC");
            String accessToken = mp.getAccessToken();
            System.out.println(accessToken);
            
//            preference = mp.createPreference("{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10}]}");
            //checkoutURL = preference.getJSONObject("response").getString("init_point");
            //Modo prueba        
            //checkoutURL = preference.getJSONObject("response").getString("sandbox_init_point");
//            checkoutURL = preference.toString();
            
        } catch (Exception ex) {
            System.err.println("No conectadoooo");
            ex.printStackTrace();
            //Logger.getLogger(MercadoPago.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public MP getMp() {
        return mp;
    }

    public void setMp(MP mp) {
        this.mp = mp;
    }

    public JSONObject getPreference() {
        return preference;
    }

    public void setPreference(JSONObject preference) {
        this.preference = preference;
    }

    public String getCheckoutURL() {
        return checkoutURL;
    }

    public void setCheckoutURL(String checkoutURL) {
        this.checkoutURL = checkoutURL;
    }
    
    
    
}
